using System;
using System.Threading.Tasks;
using SheLife.Domain.Entities;

namespace SheLife.Domain.Interfaces.Repositories
{
    /// <summary>
    /// 系统消息仓储接口
    /// </summary>
    public interface ISystemMessageRepository : IRepository<SystemMessage>
    {
        /// <summary>
        /// 根据接收用户ID获取消息列表
        /// </summary>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>消息列表</returns>
        Task<IEnumerable<SystemMessage>> GetByReceiverIdAsync(Guid receiverId);

        /// <summary>
        /// 根据发送用户ID获取消息列表
        /// </summary>
        /// <param name="senderId">发送用户ID</param>
        /// <returns>消息列表</returns>
        Task<IEnumerable<SystemMessage>> GetBySenderIdAsync(Guid senderId);

        /// <summary>
        /// 根据消息类型获取消息列表
        /// </summary>
        /// <param name="messageType">消息类型</param>
        /// <returns>消息列表</returns>
        Task<IEnumerable<SystemMessage>> GetByMessageTypeAsync(string messageType);

        /// <summary>
        /// 根据消息状态获取消息列表
        /// </summary>
        /// <param name="status">消息状态</param>
        /// <returns>消息列表</returns>
        Task<IEnumerable<SystemMessage>> GetByStatusAsync(string status);

        /// <summary>
        /// 获取用户未读消息列表
        /// </summary>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>未读消息列表</returns>
        Task<IEnumerable<SystemMessage>> GetUnreadMessagesAsync(Guid receiverId);

        /// <summary>
        /// 获取用户已读消息列表
        /// </summary>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>已读消息列表</returns>
        Task<IEnumerable<SystemMessage>> GetReadMessagesAsync(Guid receiverId);

        /// <summary>
        /// 获取消息列表（分页）
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="receiverId">接收用户ID</param>
        /// <param name="senderId">发送用户ID</param>
        /// <param name="messageType">消息类型</param>
        /// <param name="status">消息状态</param>
        /// <returns>消息列表</returns>
        Task<(IEnumerable<SystemMessage> Items, int TotalCount)> GetMessagesPagedAsync(
            int pageIndex, 
            int pageSize, 
            Guid? receiverId = null, 
            Guid? senderId = null, 
            string messageType = null, 
            string status = null);

        /// <summary>
        /// 标记消息为已读
        /// </summary>
        /// <param name="messageId">消息ID</param>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>是否成功</returns>
        Task<bool> MarkMessageAsReadAsync(Guid messageId, Guid receiverId);

        /// <summary>
        /// 批量标记消息为已读
        /// </summary>
        /// <param name="messageIds">消息ID列表</param>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>是否成功</returns>
        Task<bool> MarkMessagesAsReadAsync(IEnumerable<Guid> messageIds, Guid receiverId);

        /// <summary>
        /// 标记所有消息为已读
        /// </summary>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>是否成功</returns>
        Task<bool> MarkAllMessagesAsReadAsync(Guid receiverId);

        /// <summary>
        /// 删除消息
        /// </summary>
        /// <param name="messageId">消息ID</param>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>是否成功</returns>
        Task<bool> DeleteMessageAsync(Guid messageId, Guid receiverId);

        /// <summary>
        /// 批量删除消息
        /// </summary>
        /// <param name="messageIds">消息ID列表</param>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>是否成功</returns>
        Task<bool> DeleteMessagesAsync(IEnumerable<Guid> messageIds, Guid receiverId);

        /// <summary>
        /// 获取未读消息数量
        /// </summary>
        /// <param name="receiverId">接收用户ID</param>
        /// <returns>未读消息数量</returns>
        Task<int> GetUnreadMessageCountAsync(Guid receiverId);
    }
}